package router

import (
	"yunj/app/controller/client"
	"yunj/app/controller/client/api"
	clientMiddleware "yunj/app/middleware/client"

	"github.com/gin-gonic/gin"
)

// 客户端路由
func clientRouter(router *gin.Engine) {
	r := router.Group("")
	{
		// 错误捕获和日志中间件
		r.Use(
			gin.RecoveryWithWriter(gin.DefaultErrorWriter, func(c *gin.Context, recovered any) {
				clientMiddleware.Recover(c, recovered)
			}),
			clientMiddleware.Log(),
		)
		// 首页
		indexController := client.Index{}
		r.GET("/", indexController.Index)
		// 错误页
		ErrorController := client.Error{}
		r.Any("/error", ErrorController.Index)
		r.Any("/error.html", ErrorController.Index)
		// 关于我们
		AboutUsController := client.AboutUs{}
		r.GET("/about-us", AboutUsController.Index)
		r.GET("/about-us.html", AboutUsController.Index)
		// 分类页
		CategoryController := client.Category{}
		r.GET("/category/:id", CategoryController.Index)
		// 搜索页
		SearchController := client.Search{}
		r.GET("/search", SearchController.Index)
		r.GET("/search.html", SearchController.Index)
		// 文章详情页
		ArticleController := client.Article{}
		r.GET("/article/:id", ArticleController.Detail)

		// API
		apiRouter := router.Group("/api")
		{
			// 文章列表查询
			apiArticleController := api.Article{}
			apiRouter.POST("/article/list", apiArticleController.List)
			// guid
			apiGuidController := api.Guid{}
			apiRouter.POST("/guid/check", apiGuidController.Check)
			apiRouter.POST("/guid/valid", apiGuidController.Valid)
		}
	}

}
